//
//  MoreInformationViewController.m
//  BabyAndBabyDriver
//
//  Created by 尹宁 on 16/8/22.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "MoreInformationViewController.h"
#import "MoreInformationTableViewCell.h"
#import "DetailInformationViewController.h"
#import "MainListModel.h"

@interface MoreInformationViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *listArr;
@property (nonatomic, strong) NSNumber *count;
@end

@implementation MoreInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"通知";
    _listArr = [NSMutableArray array];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTableView];
    [self getListData];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT) style:UITableViewStyleGrouped];
    _tableView.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"MoreInformationTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:_tableView];
    _tableView.sectionFooterHeight = 0;

}

- (void)getListData
{
    YTKNetHandle *api = [[YTKNetHandle alloc]initWithUrl:@"Notice/lists.json" paramDic:@{@"token":TOKEN,@"firstRow":@0,@"listRows":@10000} RegisterApiMethod:RequestMethodPost];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        //        NSLog(@"%@", request.responseBody);
        NSDictionary *dic = request.responseBody[@"result"];
        _count = dic[@"count"];
        //        NSLog(@"%@", _count);
        //        NSLog(@"%@",dic);
        NSArray *arr = dic[@"lists"];
        for (NSDictionary *dic1 in arr) {
            MainListModel *model = [[MainListModel alloc] init];
            model.Id = dic1[@"id"];
            model.data = dic1[@"date"];
            model.name = dic1[@"name"];
            model.context = dic1[@"context"];
            
            [_listArr addObject:model];
        }
        [_tableView reloadData];
    } failure:^(YTKBaseRequest *request) {
        
    }];
}

#pragma mark - TableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _listArr.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MoreInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    MainListModel *model = _listArr[indexPath.row];
    cell.nameLabel.text = model.name;
    cell.dateLabel.text = model.data;
    cell.contextLabel.text = model.context;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailInformationViewController *detail = [[DetailInformationViewController alloc] init];
    MainListModel *model = _listArr[indexPath.row];
    detail.ID = model.Id;
    [self.navigationController pushViewController:detail animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
